
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/7/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             LinkTypeDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class LinkTypeDAL
    {
        #region  Properties
		 
		public static string FIELD_LINKTYPEID = "LinkTypeId";  
		public static string FIELD_LINKTYPENAME = "LinkTypeName";  
		public static string FIELD_DESCRIPTION = "Description"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of LinkType
        /// </summary>
        /// <param name="LinkTypeId">Primary Keys</param>
        /// <returns>Collection of LinkTypeInfo</returns>
        public static LinkTypeInfo SelectOne(int LinkTypeId)
        {
            LinkTypeInfo _LinkTypeInfo = new LinkTypeInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LinkTypeSelectOne", LinkTypeId);
                if (dr.Read())
                    setLinkTypeInfo(dr, ref _LinkTypeInfo);
                return _LinkTypeInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all LinkType
        /// </summary>
        /// <returns>Collection of LinkTypeInfo</returns>
        public static List<LinkTypeInfo> SelectAll()
        {
            List<LinkTypeInfo> lstLinkType = new List<LinkTypeInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LinkTypeSelectAll");
                setListLinkTypeInfo(ref dr, ref lstLinkType);
                return lstLinkType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="LinkTypenfo">Modify this method adapting your need</param>
        /// <returns>Collection of LinkTypeInfo</returns>
        public static List<LinkTypeInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<LinkTypeInfo> lstLinkType = new List<LinkTypeInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LinkTypeSelectByFilters");
                setListLinkTypeInfo(ref dr, ref lstLinkType);
                return lstLinkType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert LinkType
        /// </summary>
        /// <param name="LinkTypeInfo">Entity of LinkType</param>
        /// <returns>error code</returns>
        public static int Insert(LinkTypeInfo _LinkTypeInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LinkTypeInsert" 
											, _LinkTypeInfo.LinkTypeName
											, _LinkTypeInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update LinkType
        /// </summary>
        /// <param name="LinkTypeInfo">Entity of LinkType</param>
        /// <returns>error code</returns>
        public static int Update(LinkTypeInfo _LinkTypeInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LinkTypeUpdate"
											, _LinkTypeInfo.LinkTypeId
											, _LinkTypeInfo.LinkTypeName
											, _LinkTypeInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="LinkTypeId">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int LinkTypeId)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LinkTypeDelete", LinkTypeId);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListLinkTypeInfo(ref SqlDataReader dr, ref List<LinkTypeInfo> lstLinkType)
        {
            LinkTypeInfo _LinkTypeInfo = null;
            while (dr.Read())
            {
                _LinkTypeInfo = new LinkTypeInfo();
                setLinkTypeInfo(dr, ref _LinkTypeInfo);
                lstLinkType.Add(_LinkTypeInfo);
            }
        }

        private static void setLinkTypeInfo(SqlDataReader dr, ref LinkTypeInfo _LinkTypeInfo)
        {
			_LinkTypeInfo.LinkTypeId = dr[LinkTypeDAL.FIELD_LINKTYPEID] != DBNull.Value ? Convert.ToInt32(dr[LinkTypeDAL.FIELD_LINKTYPEID]) : 0;
			_LinkTypeInfo.LinkTypeName = dr[LinkTypeDAL.FIELD_LINKTYPENAME] != DBNull.Value ? Convert.ToString(dr[LinkTypeDAL.FIELD_LINKTYPENAME]) : string.Empty;
			_LinkTypeInfo.Description = dr[LinkTypeDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[LinkTypeDAL.FIELD_DESCRIPTION]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[conf_LinkType]";

        #endregion
    }
}

		